home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / ctlib100.zip / INSTALL.LZH / ARRAYSH4.PAS < prev    next >
Pascal/Delphi Source File  |  1996-10-12  |  3KB  |  103 lines

  1. {**************************************************************************}
  2. {*  BitSoft Development, L.L.C.                                           *}
  3. {*  Copyright (C) 1995, 1996 BitSoft Development, L.L.C.                  *}
  4. {*  All rights reserved.                                                  *}
  5. {*  Containers Library demo                                               *}
  6. {**************************************************************************}
  7.  
  8. program ArraysHuge4;
  9.  
  10. {$X+}
  11.  
  12. { Sample program for accesing directly a huge object array }
  13.  
  14. uses Objects, Containr, ctArrays,
  15.      {$ifdef Windows}
  16.      WinCtr;
  17.      {$else}
  18.      Crt;
  19.      {$endif}
  20.  
  21. type
  22.   PWeatherInfo = ^TWeatherInfo;
  23.   TWeatherInfo = object(TObject)
  24.       Location : PString;
  25.       Humidity : Integer;
  26.       Rain : Integer;
  27.     constructor Init(ALocation : string; AHumidity, ARain : Integer);
  28.     destructor Done; virtual;
  29.   end; { TWeatherInfo }
  30.  
  31. constructor TWeatherInfo.Init(ALocation : string; AHumidity, ARain : Integer);
  32. begin
  33.   Location := NewStr(ALocation);
  34.   Humidity := AHumidity;
  35.   Rain := ARain;
  36. end;
  37.  
  38. destructor TWeatherInfo.Done;
  39. begin
  40.   DisposeStr(Location);
  41. end;
  42.  
  43. procedure DisplayWeatherData(WeatherData : PSequence);
  44. var
  45.   i : Integer;
  46. begin
  47.   with WeatherData^ do
  48.     for i := FirstIndex to LastIndex do
  49.       with PWeatherInfo(At(i))^ do
  50.         writeln('Hour: ', i:2, ':00', '':3, Location^, '':20 -
  51.           Length(Location^), Humidity, '':5, Rain:5);
  52. end;
  53.  
  54. procedure FindLowHumidityValue(WeatherData : PSequence);
  55. var
  56.   Item : Pointer;
  57.   Index : LongInt;
  58.  
  59.   function HasLowHumidity(Item : PWeatherInfo) : Boolean; far;
  60.   begin
  61.     HasLowHumidity := (Item^.Humidity < 22);
  62.   end;
  63.  
  64. begin
  65.   Item := WeatherData^.FirstThat(@HasLowHumidity, Index);
  66.   writeln ('First with low humidity (H < 22):');
  67.   with PWeatherInfo(Item)^ do
  68.     writeln('Hour: ', Index:2, ':00', '':3, Location^, '':20 -
  69.       Length(Location^), Humidity, '':5, Rain:5);
  70. end;
  71.  
  72. var
  73.   MorningWeatherData : PHugeObjectArray;
  74.  
  75. begin
  76.   ClrScr;
  77.  
  78.   { Create the array }
  79.   MorningWeatherData := New(PHugeObjectArray, Init(7, 11,
  80.     SizeOf(TWeatherInfo)));
  81.  
  82.   { Insert the items in the array }
  83.   with MorningWeatherData^ do
  84.   begin
  85.     with PWeatherInfo(At(7))^ do
  86.       Init('Miami', 34, 0);
  87.     with PWeatherInfo(At(8))^ do
  88.       Init('Helsinski', 23, 3);
  89.     with PWeatherInfo(At(9))^ do
  90.       Init('Canada', 26, 2);
  91.     with PWeatherInfo(At(10))^ do
  92.       Init('Berlin', 28, 5);
  93.     with PWeatherInfo(At(11))^ do
  94.       Init('Melbourne', 20, 0);
  95.   end; { with }
  96.  
  97.   DisplayWeatherData(MorningWeatherData);
  98.   writeln;
  99.   FindLowHumidityValue(MorningWeatherData);
  100.  
  101.   { Dispose of the array }
  102.   Dispose(MorningWeatherData, Done);
  103. end.